<template>
  <view>
    <view class="AI-card">
      <image src="/static/other/AI-shibie.svg" mode="widthFix"></image>
      <text @click="ai">身份证智能识别</text>
    </view>
    <view class="xinguan-view">
      <view class="xinguan-flex">
        <text>真实姓名</text>
        <input placeholder="请输入姓名" v-model="obj.name" placeholder-class="input-style"/>
      </view>
      <view class="xinguan-flex">
        <text>性别</text>
        <picker mode="selector" class="flex-left" :range=arr @change="change">
          <view>
            <text>{{ obj.sex }}</text>
            <image src="/static/other/gengduo.svg"></image>
          </view>
        </picker>
      </view>
      <view class="xinguan-flex">
        <text>出生日期</text>
        <picker mode="date" class="flex-left" @change="change1">
          <view>
            <text>{{ obj.born }}</text>
            <image src="/static/other/gengduo.svg"></image>
          </view>
        </picker>
      </view>
      <view class="xinguan-flex">
        <text>成员关系</text>
        <picker mode="selector" class="flex-left" :range=arr1 @change="change2">
          <view>
            <text>{{ obj.relation }}</text>
            <image src="/static/other/gengduo.svg"></image>
          </view>
        </picker>
      </view>
      <view class="xinguan-flex">
        <text>身份证</text>
        <input placeholder="请输入身份证" v-model="obj.id_card" placeholder-class="input-style"/>
      </view>
      <view class="xinguan-flex">
        <text>手机号</text>
        <input placeholder="请输入手机号" v-model="obj.phone" type="number" placeholder-class="input-style"/>
      </view>
    </view>
    <view style="height:300rpx"></view>
    <view class="submit">
      <text @click="no">取消</text>
      <text @click="submit">确认添加</text>
    </view>
  </view>
</template>

<script>
import {aicard, patientres} from "../../utils/API/homeapi";
import {upload} from "../../utils/API/img";

export default {
  data() {
    return {
      arr: ["男", '女'],
      arr1: ["自己", '父母', '其他'],
      obj: {
        name: "",
        sex: '',
        born: "",
        relation: '',
        id_card: "",
        phone: ""
      }
    };
  },
  methods: {
    //男女
    change(e) {
      if (e.detail.value === "0") {
        this.obj.sex = "男"
      } else {
        this.obj.sex = "女"
      }
    },
    //出生日期
    change1(e) {
      this.obj.born = e.detail.value
    },
    //成员关系
    change2(e) {
      switch (e.detail.value) {
        case "0":
          this.obj.relation = "自己"
          break;
        case "1":
          this.obj.relation = "父母"
          break;
        case "2":
          this.obj.relation = "其他"
          break;
      }
    },
    //身份证AI识别
    async ai() {
      let {data} = await upload(aicard, '加载中')
      this.obj.name = data.name
      this.obj.sex = data.sex
      this.obj.born = data.born
      this.obj.id_card = data.id_card
    },
    no() {
      wx.navigateBack({
        delta: 1
      })
    },
    async submit() {
      let data = await patientres(this.obj)
      if (data.msg === '提交成功') {
        wx.showToast({
          title: data.msg,
          icon: 'success',
          duration: 1000
        })
        setTimeout(() => {
          wx.navigateBack({
            delta: 1
          })
        }, 1000)
      }
    }

  }
}
</script>

<style lang="scss">
@import url('../../static/common-style/form.css');

page {
  background-color: #f6f6f6;
}

.AI-card {
  display: flex;
  align-items: center;
  background-color: #ffffff;
  font-size: 35rpx;
  border-radius: 15rpx;
  padding: 30rpx 20rpx;
  margin: 20rpx 20rpx 50rpx 20rpx;
}

.AI-card image {
  width: 80rpx;
  height: 80rpx;
  margin-right: 20rpx;
  display: block;
}
</style>
